package cn.stronglink.assetmanage.business.check.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import java.util.List;
import java.util.zip.Inflater;

import cn.stronglink.assetmanage.R;
import cn.stronglink.assetmanage.entity.Check;
import cn.stronglink.assetmanage.index.view.onRecyclerListener;

import static android.view.View.inflate;

/**
 * 表单列表
 * @author zww
 *         2018 2018/6/10 18:13
 */
public class CheckListAdapter extends RecyclerView.Adapter<CheckListAdapter.ViewHolder> {
    private Context mContext;
    private List<Check> datas;
    private onRecyclerListener listener;

    public CheckListAdapter(Context context) {
        this.mContext = context;
    }

    @Override
    public CheckListAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.item_check_list,parent, false);
        return new CheckListAdapter.ViewHolder(view, listener);
    }

    @Override
    public void onBindViewHolder(CheckListAdapter.ViewHolder holder, int position) {
        Check check = datas.get(position);
        holder.bindRepo(check, position);
    }

    @Override
    public int getItemCount() {

        return datas == null ? 0 : datas.size();
    }

    public void setOnItemClickListener(onRecyclerListener listener) {
        this.listener = listener;
    }

    public void notifyDatasChanged(List<Check> data) {
        this.datas = data;
        notifyDataSetChanged();
    }

    public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {

        private final TextView tv_order_name;
        private onRecyclerListener listener;

        public ViewHolder(View itemView, onRecyclerListener listener) {
            super(itemView);
            this.listener = listener;
            tv_order_name = (TextView)itemView.findViewById(R.id.tv_check_order_name);
            itemView.setOnClickListener(this);
        }

        public void bindRepo(Check repo, int position) {
            tv_order_name.setText(repo.getId_());
        }

        @Override
        public void onClick(View v) {
            if (listener != null) {
                listener.onItemClicked(v, getAdapterPosition());
            }
        }
    }

}
